{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5e495114",
   "metadata": {},
   "source": [
    "-------\n",
    "* 日期：2022-11-23\\week14（周三）\n",
    "* 课程：python\n",
    "* 记录人：刘石珍\n",
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba340118",
   "metadata": {},
   "source": [
    "# 1.函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "897a03e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "def greet_user():\n",
    "    \"\"\"用户问候语\"\"\"\n",
    "    print(\"hello world~\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bccdfb3b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world~\n"
     ]
    }
   ],
   "source": [
    "greet_user()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c51382bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "def greet_user(username):\n",
    "    \"\"\"用户问候语\"\"\"\n",
    "    print(\"hello\",username)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ab9705d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello Alex\n"
     ]
    }
   ],
   "source": [
    "greet_user(username=\"Alex\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "519c6aeb",
   "metadata": {},
   "source": [
    "# 函数的意义：  \n",
    "1.重复使用  \n",
    "2.可以给了解python的人使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "440e30b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：广州南方学院新闻网站url实践函数  \n",
    "def NFU_NEWS_URL(分类,页码):\n",
    "    \"\"\"广州南方学院新闻页面URL数据\n",
    "       分类只需要写对应的编码就可以，对应的页码如下\n",
    "       分类包含:【学校要闻：xxyw,校园动态：xydt,通知公告：tzgg,招投标：ztb】\n",
    "       页码包含：【113，106，37，27】\"\"\"\n",
    "    for i in range(页码):\n",
    "        print(\"https://www.edu.cn/\" + 分类 + \"/index\" + str(i) + \".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "512fcd25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function NFU_NEWS_URL in module __main__:\n",
      "\n",
      "NFU_NEWS_URL(分类, 页码)\n",
      "    广州南方学院新闻页面URL数据\n",
      "    分类只需要写对应的编码就可以，对应的页码如下\n",
      "    分类包含:【学校要闻：xxyw,校园动态：xydt,通知公告：tzgg,招投标：ztb】\n",
      "    页码包含：【113，106，37，27】\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(NFU_NEWS_URL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "ec8b0645",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.edu.cn/xxyw/index0.htm\n",
      "https://www.edu.cn/xxyw/index1.htm\n",
      "https://www.edu.cn/xxyw/index2.htm\n",
      "https://www.edu.cn/xxyw/index3.htm\n",
      "https://www.edu.cn/xxyw/index4.htm\n",
      "https://www.edu.cn/xxyw/index5.htm\n",
      "https://www.edu.cn/xxyw/index6.htm\n",
      "https://www.edu.cn/xxyw/index7.htm\n",
      "https://www.edu.cn/xxyw/index8.htm\n",
      "https://www.edu.cn/xxyw/index9.htm\n",
      "https://www.edu.cn/xxyw/index10.htm\n",
      "https://www.edu.cn/xxyw/index11.htm\n",
      "https://www.edu.cn/xxyw/index12.htm\n",
      "https://www.edu.cn/xxyw/index13.htm\n",
      "https://www.edu.cn/xxyw/index14.htm\n",
      "https://www.edu.cn/xxyw/index15.htm\n",
      "https://www.edu.cn/xxyw/index16.htm\n",
      "https://www.edu.cn/xxyw/index17.htm\n",
      "https://www.edu.cn/xxyw/index18.htm\n",
      "https://www.edu.cn/xxyw/index19.htm\n",
      "https://www.edu.cn/xxyw/index20.htm\n",
      "https://www.edu.cn/xxyw/index21.htm\n",
      "https://www.edu.cn/xxyw/index22.htm\n",
      "https://www.edu.cn/xxyw/index23.htm\n",
      "https://www.edu.cn/xxyw/index24.htm\n",
      "https://www.edu.cn/xxyw/index25.htm\n",
      "https://www.edu.cn/xxyw/index26.htm\n",
      "https://www.edu.cn/xxyw/index27.htm\n",
      "https://www.edu.cn/xxyw/index28.htm\n",
      "https://www.edu.cn/xxyw/index29.htm\n",
      "https://www.edu.cn/xxyw/index30.htm\n",
      "https://www.edu.cn/xxyw/index31.htm\n",
      "https://www.edu.cn/xxyw/index32.htm\n",
      "https://www.edu.cn/xxyw/index33.htm\n",
      "https://www.edu.cn/xxyw/index34.htm\n",
      "https://www.edu.cn/xxyw/index35.htm\n",
      "https://www.edu.cn/xxyw/index36.htm\n",
      "https://www.edu.cn/xxyw/index37.htm\n",
      "https://www.edu.cn/xxyw/index38.htm\n",
      "https://www.edu.cn/xxyw/index39.htm\n",
      "https://www.edu.cn/xxyw/index40.htm\n",
      "https://www.edu.cn/xxyw/index41.htm\n",
      "https://www.edu.cn/xxyw/index42.htm\n",
      "https://www.edu.cn/xxyw/index43.htm\n",
      "https://www.edu.cn/xxyw/index44.htm\n",
      "https://www.edu.cn/xxyw/index45.htm\n",
      "https://www.edu.cn/xxyw/index46.htm\n",
      "https://www.edu.cn/xxyw/index47.htm\n",
      "https://www.edu.cn/xxyw/index48.htm\n",
      "https://www.edu.cn/xxyw/index49.htm\n",
      "https://www.edu.cn/xxyw/index50.htm\n",
      "https://www.edu.cn/xxyw/index51.htm\n",
      "https://www.edu.cn/xxyw/index52.htm\n",
      "https://www.edu.cn/xxyw/index53.htm\n",
      "https://www.edu.cn/xxyw/index54.htm\n",
      "https://www.edu.cn/xxyw/index55.htm\n",
      "https://www.edu.cn/xxyw/index56.htm\n",
      "https://www.edu.cn/xxyw/index57.htm\n",
      "https://www.edu.cn/xxyw/index58.htm\n",
      "https://www.edu.cn/xxyw/index59.htm\n",
      "https://www.edu.cn/xxyw/index60.htm\n",
      "https://www.edu.cn/xxyw/index61.htm\n",
      "https://www.edu.cn/xxyw/index62.htm\n",
      "https://www.edu.cn/xxyw/index63.htm\n",
      "https://www.edu.cn/xxyw/index64.htm\n",
      "https://www.edu.cn/xxyw/index65.htm\n",
      "https://www.edu.cn/xxyw/index66.htm\n",
      "https://www.edu.cn/xxyw/index67.htm\n",
      "https://www.edu.cn/xxyw/index68.htm\n",
      "https://www.edu.cn/xxyw/index69.htm\n",
      "https://www.edu.cn/xxyw/index70.htm\n",
      "https://www.edu.cn/xxyw/index71.htm\n",
      "https://www.edu.cn/xxyw/index72.htm\n",
      "https://www.edu.cn/xxyw/index73.htm\n",
      "https://www.edu.cn/xxyw/index74.htm\n",
      "https://www.edu.cn/xxyw/index75.htm\n",
      "https://www.edu.cn/xxyw/index76.htm\n",
      "https://www.edu.cn/xxyw/index77.htm\n",
      "https://www.edu.cn/xxyw/index78.htm\n",
      "https://www.edu.cn/xxyw/index79.htm\n",
      "https://www.edu.cn/xxyw/index80.htm\n",
      "https://www.edu.cn/xxyw/index81.htm\n",
      "https://www.edu.cn/xxyw/index82.htm\n",
      "https://www.edu.cn/xxyw/index83.htm\n",
      "https://www.edu.cn/xxyw/index84.htm\n",
      "https://www.edu.cn/xxyw/index85.htm\n",
      "https://www.edu.cn/xxyw/index86.htm\n",
      "https://www.edu.cn/xxyw/index87.htm\n",
      "https://www.edu.cn/xxyw/index88.htm\n",
      "https://www.edu.cn/xxyw/index89.htm\n",
      "https://www.edu.cn/xxyw/index90.htm\n",
      "https://www.edu.cn/xxyw/index91.htm\n",
      "https://www.edu.cn/xxyw/index92.htm\n",
      "https://www.edu.cn/xxyw/index93.htm\n",
      "https://www.edu.cn/xxyw/index94.htm\n",
      "https://www.edu.cn/xxyw/index95.htm\n",
      "https://www.edu.cn/xxyw/index96.htm\n",
      "https://www.edu.cn/xxyw/index97.htm\n",
      "https://www.edu.cn/xxyw/index98.htm\n",
      "https://www.edu.cn/xxyw/index99.htm\n",
      "https://www.edu.cn/xxyw/index100.htm\n",
      "https://www.edu.cn/xxyw/index101.htm\n",
      "https://www.edu.cn/xxyw/index102.htm\n",
      "https://www.edu.cn/xxyw/index103.htm\n",
      "https://www.edu.cn/xxyw/index104.htm\n",
      "https://www.edu.cn/xxyw/index105.htm\n",
      "https://www.edu.cn/xxyw/index106.htm\n",
      "https://www.edu.cn/xxyw/index107.htm\n",
      "https://www.edu.cn/xxyw/index108.htm\n",
      "https://www.edu.cn/xxyw/index109.htm\n",
      "https://www.edu.cn/xxyw/index110.htm\n",
      "https://www.edu.cn/xxyw/index111.htm\n",
      "https://www.edu.cn/xxyw/index112.htm\n"
     ]
    }
   ],
   "source": [
    "NFU_NEWS_URL(\"xxyw\",113)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5cd3c6c",
   "metadata": {},
   "source": [
    "# 2.模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "22c602dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import college_url_crawl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "10419d7f",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'college_url_crawl' has no attribute 'NFU_NEWS_URL'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Input \u001b[1;32mIn [29]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m help(\u001b[43mcollege_url_crawl\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mNFU_NEWS_URL\u001b[49m)\n",
      "\u001b[1;31mAttributeError\u001b[0m: module 'college_url_crawl' has no attribute 'NFU_NEWS_URL'"
     ]
    }
   ],
   "source": [
    "help(college_url_crawl.NFU_NEWS_URL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "dc1cca94",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'college_url_crawl' has no attribute 'NFU_NEWS_URL'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Input \u001b[1;32mIn [30]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mcollege_url_crawl\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mNFU_NEWS_URL\u001b[49m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mxydt\u001b[39m\u001b[38;5;124m\"\u001b[39m,\u001b[38;5;241m106\u001b[39m)\n",
      "\u001b[1;31mAttributeError\u001b[0m: module 'college_url_crawl' has no attribute 'NFU_NEWS_URL'"
     ]
    }
   ],
   "source": [
    "college_url_crawl.NFU_NEWS_URL(\"xydt\",106)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b4ccdd85",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
